package com.hz.zbl.model.request;

import com.alibaba.fastjson2.JSON;
import com.hz.zbl.model.enums.ApiResponseCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse<T> {


    public String code;

    public String message;

    public T data;



    public ApiResponse(String code, String message){

        this.code = code;

        this.message= message;
    }


    /**
     * 通用成功方法，需传入数据
     * @param data 需要传入的数据
     * @return JSON 返回json
     * @param <T> 参数类型
     */
    public static <T> String ok(T data){

        ApiResponse<T> res = new ApiResponse<>(ApiResponseCodeEnum.SUCCESS.getCode(),
                                                ApiResponseCodeEnum.SUCCESS.getMessage(),data);

        return JSON.toJSONString(res);
    }


    /**
     * 通用 资源无权限访问
     * @return JSON
     */
    public static String intForbidden(){
        ApiResponse res = new ApiResponse<>(ApiResponseCodeEnum.INTERFACE_FORBIDDEN.getCode(),
                                            ApiResponseCodeEnum.INTERFACE_FORBIDDEN.getMessage());

        return JSON.toJSONString(res);
    }


    /**
     * 通用 访问资源不存在
     * @return JSON
     */
    public static String resNotFound(){
        ApiResponse res = new ApiResponse<>(ApiResponseCodeEnum.RESOURCE_NOT_FOUND.getCode(),
                                            ApiResponseCodeEnum.RESOURCE_NOT_FOUND.getMessage());

        return JSON.toJSONString(res);
    }


    /**
     * 通用 资源接口错误
     * @return JSON
     */
    public static String intError(){
        ApiResponse res = new ApiResponse<>(ApiResponseCodeEnum.INTERFACE_ERROR.getCode(),
                                            ApiResponseCodeEnum.INTERFACE_ERROR.getMessage());

        return JSON.toJSONString(res);
    }


    /**
     * 通用 系统错误
     * @return JSON
     */
    public static String sysError(){
        ApiResponse res = new ApiResponse<>(ApiResponseCodeEnum.SYSTEM_ERROR.getCode(),
                                            ApiResponseCodeEnum.SYSTEM_ERROR.getMessage());

        return JSON.toJSONString(res);
    }


    //userLogin


    public static String userLogin(String message){
        ApiResponse res = new ApiResponse<>(ApiResponseCodeEnum.SYSTEM_ERROR.getCode(),
                                            ApiResponseCodeEnum.SYSTEM_ERROR.getMessage());

        return JSON.toJSONString(res);
    }




}
